<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <%= stylesheet_link_tag 'attachment' %>
    <%= javascript_include_tag 'jquery', 'jquery-ujs', 'application' %>
  </head>
  <body>
    <% form_for :attachment, url(:admin, :create_attachment), :id => "attachment_form", :multipart => true do |f| -%>
      <%= f.file_field :file, :onchange => "upload(this.value);" %>
      <span id="spinner" style="display:none;">上传中 <%= image_tag "spinner.gif" %></span>
      <span id="upload-tip" style="display:none;"></span>
    <% end %>
    
    <script type="text/javascript">
      function upload(fileName) {
        $('#upload-tip').html("文件正在上传中，请等待完成后再提交").show();
        $('#spinner').show();
        var iframes = window.parent.$("#attachment_iframes")[0];
        iframes.appendChild(iframes.getElementsByTagName('iframe')[0].cloneNode(false));
        $('#attachment_form').submit();
      }
    </script>
  </body>
</html>
